﻿using UnityEngine;

public class BallColors : MonoBehaviour 
{
	public Material[] materials;
		
	public bool IsMeshesTargetColor(MeshRenderer[] meshes, Color col) 
	{	
		foreach (MeshRenderer m in meshes)
		{
			if (m.material.color != col)
			{
				return false;
			}
		}
		
		return true;
	}
	
	public Color NormalizeColor(Color col) 
	{
		col.r = Mathf.Clamp(col.r, 0.0f, 1.0f);
		col.g = Mathf.Clamp(col.g, 0.0f, 1.0f);
		col.b = Mathf.Clamp(col.b, 0.0f, 1.0f);		
		col.a = Mathf.Clamp(col.a, 0.0f, 1.0f);
		
		return col;
	}
	
	public Color GetColorFromName(string name)
	{
		Color col = Color.clear;
		
		foreach (Material m in materials)
		{
			if (string.Equals(m.name.ToLower(), name.ToLower()))
			{
				col = m.color;
				break;
			}
		}
		return col;
	}
		
}
